{extend name="main"}
{block name="style"}
<style type="text/css">
	.flex-lable{width: 140px;color: #6c757d;text-align: right;padding-right: 10px;}
	.w-100px{width: 100px;}
</style>
{/block}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right" class="flex py-3">

	  <el-form-item label="搜索类型" prop="search_type" class="flex mb-0 pl-3">
	  	<el-select v-model="search.search_type" placeholder="请选择" class="w-100px">
		    <el-option key="id"label="公司ID"value="id"></el-option>
		    <el-option key="uid"label="UID"value="uid"></el-option>
		    <el-option key="uscc"label="统一社会信用代码"value="uscc"></el-option>
		    <el-option key="company_name"label="公司名"value="company_name"></el-option>
		    <el-option key="contacts_mobile"label="联系人手机号"value="contacts_mobile"></el-option>
		    <el-option key="contacts_email"label="联系人邮箱"value="contacts_email"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="企业认证" prop="attestation" class="flex mb-0 pl-3">
	  	<el-select v-model="search.attestation" placeholder="请选择" class="w-100px">
		    <el-option key="all"label="全部"value="all"></el-option>
		    <el-option v-for="v in attestation" :key="v.value":label="v.title":value="v.value"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="套餐" prop="vip_level" class="flex mb-0 pl-3">
	  	<el-select v-model="search.vip_level" placeholder="请选择" class="w-100px">
		    <el-option key="all"label="全部"value="all"></el-option>
		    <el-option v-for="v in vip" :key="v.level":label="v.title":value="v.level" v-if="v.is_company"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item :label="getSearchType()" prop="key" class="flex mb-0 pl-3">
	    <el-input v-model="search.key" placeholder="请输入你想搜索的关键词"></el-input>
	  </el-form-item>

	  <el-form-item class="flex mb-0 pl-3">
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive">
		<el-table
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB"
    		@selection-change="handleSelectionChange">
		  <el-table-column
			  type="selection"
			  width="55">
		  </el-table-column>
	      <el-table-column
	        prop="uid"
	        label="UID"
	        width="100">
	      </el-table-column>
	      <el-table-column
	      	prop="title"
	        label="公司信息"
	        min-width="200">
		      <template slot-scope="scope">
		      	<div>
		      	<div>{{scope.row.title}}</div>
		      	<div class="text-primary">{{scope.row.mobile}}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="企业认证"
	        width="120">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button v-for="v in attestation" :type="v.type" size="minism"
		      		v-if="scope.row.attestation==v.value">{{v.title}}</el-button>
						</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="职位数"
	        width="120">
		      <template slot-scope="scope">
		      	<div>
			      	<div><span class="text-danger">{{scope.row.jobs_count}}</span>个</div>
			      	<el-link type="primary" :href="'/jobs/addJobs/'+scope.row.id" :underline="false" target="_blank" v-if="scope.row.attestation==3">添加</el-link>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="app_name"
	        label="来源"
	        width="160">
	      </el-table-column>
	      <el-table-column
	        label="会员"
	        width="160">
		      <template slot-scope="scope">
		      	<div>
			      	<div>{{scope.row.vip_title}}</div>
			      	<div v-if="scope.row.company_vip_time">{{scope.row.company_vip_time}}</div>
			      	<div v-else>不限</div>
		      	</div>
		      </template>

	      </el-table-column>
	      <el-table-column
	        label="名企"
	        width="100">
		      <template slot-scope="scope">
					<div>
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.is_famous==1 || scope.row.is_famous=='loading'"
		      		:loading="scope.row.is_famous=='loading'">是</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else-if="scope.row.is_famous==0 || scope.row.is_famous=='loading'" 
		      		:loading="scope.row.is_famous=='loading'">否</el-button>
						</transition>
					</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="创建/更新/刷新时间"
	        width="180">
		      <template slot-scope="scope">
		      	<div class="small">
		          <div>{{ scope.row.create_time }}</div>
		          <div>{{ scope.row.update_time }}</div>
		          <div>{{ scope.row.refresh_time }}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="160">
		      <template slot-scope="scope">
		        <el-button
		            type="success"
		            plain
		            round
		            size="minism"
		            @click="setCompanyDelete(scope)">
		            恢复
		        </el-button>
		        <el-button
		            type="danger"
		            plain
		            round
		            size="minism"
		            @click="setCompanyDeleteForce(scope)">
		            彻底删除
		        </el-button>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200,500,1000]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="admin"}
	var admin=[];
	{else/}
	var admin={:json_encode($admin,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="attestation"}
	var attestation=[];
	{else/}
	var attestation={:json_encode($attestation,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="nature"}
	var nature=[];
	{else/}
	var nature={:json_encode($nature,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="finance"}
	var finance=[];
	{else/}
	var finance={:json_encode($finance,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="industry"}
	var industry=[];
	{else/}
	var industry={:json_encode($industry,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="size_type"}
	var size_type=[];
	{else/}
	var size_type={:json_encode($size_type,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="corporate_welfare"}
	var corporate_welfare=[];
	{else/}
	var corporate_welfare={:json_encode($corporate_welfare,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="vip"}
	var vip=[];
	{else/}
	var vip={:json_encode($vip,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var loading=null;
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			vip:vip,
			labelPosition:'right',
			drawerHandle:false,
			drawerHandleFind:{},
			admin:admin,
			adviser:{id:0},
			attestation:attestation,
			nature:nature,
			finance:finance,
			industry:industry,
			size_type:size_type,
			corporate_welfare:corporate_welfare,
			multipleSelection:[],
			search:{
				{notempty name=":request()->get('uid')"}
				search_type:'uid',
				key:'{:request()->get('uid')}',
				{elseif request()->get('id')/}
				search_type:'id',
				key:'{:request()->get('id')}',
				{elseif request()->get('uscc')/}
				search_type:'uscc',
				key:'{:request()->get('uscc')}',
				{elseif request()->get('company_name')/}
				search_type:'company_name',
				key:'{:request()->get('company_name')}',
				{elseif request()->get('contacts_mobile')/}
				search_type:'contacts_mobile',
				key:'{:request()->get('contacts_mobile')}',
				{elseif request()->get('contacts_email')/}
				search_type:'contacts_email',
				key:'{:request()->get('contacts_email')}',
				{else/}
				search_type:'id',
				key:'',
				{/notempty}
				attestation:'all',
				vip_level:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
			giveFormVip:'',
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
		    toggleSelection(rows) {
		        if (rows) {
		          rows.forEach(row => {
		            this.$refs.tableList.toggleRowSelection(row);
		          });
		        } else {
		          this.$refs.tableList.clearSelection();
		        }
		    },
		    handleSelectionChange(val) {
		        this.multipleSelection = val;
		    },
	    	getSearchType(){
	    		var text='公司ID';
	    		switch(this.search.search_type){
	    			case 'id':
	    				text='公司ID';
	    				break;
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'uscc':
	    				text='统一社会信用代码';
	    				break;
	    			case 'company_name':
	    				text='公司名';
	    				break;
	    			case 'contacts_mobile':
	    				text='联系人手机号';
	    				break;
	    			case 'contacts_email':
	    				text='联系人邮箱';
	    				break;
	    		}
	    		return text;
	    	},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	    	setCompanyDelete(scope){
	    		var _this=this;
		        _this.$confirm('确定恢复《'+scope.row.title+'》吗？', '提示', {
		          confirmButtonText: '恢复',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		    		$.getJSON('/company/setCompanyDelete/'+scope.row.id,function(ret){
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.tableData.splice(scope.$index,1);
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
		        }).catch(() => {
	  				XYBase.msg('已取消');
		        });
	    	},
	    	setCompanyDeleteForce(scope){
	    		var _this=this;
		        _this.$confirm('确定彻底删除《'+scope.row.title+'》吗？', '提示', {
		          confirmButtonText: '确定',
		          cancelButtonText: '取消',
		          type: 'error'
		        }).then(() => {
		    		$.getJSON('/company/setCompanyDelete/'+scope.row.id+'?force=1',function(ret){
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.tableData.splice(scope.$index,1);
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
		        }).catch(() => {
	  				XYBase.msg('已取消');
		        });
	    	},
		    initHtml() {
		    	var _this=this;
		    	_this.search.ajax=true;
					$.ajax({
						url:'',
						type:'get',
						data:_this.search,
						dataType:'json',
						error:function(err){
		      				_this.search.ajax=false;
							XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
		      				_this.search.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									_this.search.total=ret.data.total;
									_this.tableData=ret.data.data;
								}else{
									XYBase.msg(ret.msg);
								}
							}else{
								XYBase.error(XYBase.config.system_network_error);
							}
						}
					});
				},
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}